package com.example.lotterysystem.dao.mapper;

import com.example.lotterysystem.dao.dataobject.PrizeDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author xuejiao
 * Data 2025/5/3 15:40
 */
@Mapper
public interface PrizeMapper {



    @Insert("insert into lottery_system.prize (name,image_url,price,description)" +
    " values (#{name}, #{imageUrl}, #{price},#{description})")
    @Options(useGeneratedKeys = true,keyProperty = "id", keyColumn = "id")
    int insert(PrizeDO prizeDO);

    @Select("select count(1) from lottery_system.prize")
    int count();

    @Select("select * from lottery_system.prize order by id desc limit #{offset}, #{pageSize}")
    List<PrizeDO> selectPrizeList(@Param("offset") Integer offset,
                                  @Param("pageSize") Integer pageSize);

    @Select("<script>" +
            " select id from lottery_system.prize" +
            " where id in" +
            " <foreach item='item' collection='items' open='(' separator=',' close=')'>" +
            " #{item}" +
            " </foreach>" +
            " </script>")
    List<Long> selectExistByIds(@Param("items") List<Long> ids);

    @Select("<script>" +
            " select * from lottery_system.prize" +
            " where id in" +
            " <foreach item='item' collection='items' open='(' separator=',' close=')'>" +
            " #{item}" +
            " </foreach>" +
            " </script>")
    List<PrizeDO> batchSelectByIds(@Param("items") List<Long> ids);

    @Select("select * from lottery_system.prize where id = #{id}")
    PrizeDO selectById(@Param("id") Long id);
}
